<template>
	<view>
		<view class="list setting-list">
		<!-- 	<view class="list-item1" @click="uploadImg(1)">
				<text class="list-item-text">头像</text>
				<view class="list-item-right">
					<image :src="avatar"  style="border-radius: 50%;width: 110upx;height: 110upx;"></image>
					<text class="cl-icon cl-icon-arrow-right"></text>
					</view>
			</view>
			<view class="list-item" @click="uploadImg(2)">
				<text class="list-item-text">昵称</text>
				<view class="list-item-right">{{nickname}}
				<uni-icons type="right" size="20" color="#B7B7B7"></uni-icons>
				</view>
			</view> -->
			<view class="list-item">
				<text class="list-item-text">手机号</text>
				<view class="list-item-right">{{mobile}}</view>
			</view>
			
		<!-- 	<view class="list-item" @click="toCard">
				<text class="list-item-text">银行卡号</text>
				<text class="cl-icon cl-icon-arrow-right"></text>
			</view> -->
			
		<!-- 	<view class="list-item" @click="changeLoginPwd(0)">
				<text class="list-item-text">登录密码</text>
				<uni-icons type="right" size="20" color="#B7B7B7"></uni-icons>				
			</view> -->
			<view class="list-item" @click="changeLoginPwd(1)">
				<text class="list-item-text">支付密码</text>
				<uni-icons type="right" size="20" color="#B7B7B7"></uni-icons>	
			</view>
			<!-- <view class="list-item" @click="checkUpdate">
				<text class="list-item-text">版本号</text>
				<view class="list-item-right">{{Version}}</view>
			</view>
			<view class="list-item" @click="clearStorage">
				<text class="list-item-text">清空缓存</text>
				<view class="list-item-right">{{storageSize}}</view>
			</view> -->
			
		
		</view>

		<view class="but" @click="outlogin">退出登录</view>
		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog ref="inputClose"  mode="input" title="修改昵称" value=""
							placeholder="请输入昵称" @confirm="dialogInputConfirm"></uni-popup-dialog>
		</uni-popup>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				mobile:'',
				Version:'',
                storageSize : '',
				nickname:'',
				config: {
					service_mobile: '',
					about: ''
				},
				isSetPayPwd: false,
				login: {
					login_pwd: '',
					new_login_pwd: '',
                    code:''
				},
				pay: {
					pay_pwd: '',
					new_pay_pwd: '',
                    code:''
                },
               	avatar:'',
			}
		},

		onLoad(option) {
            this.getStorageSize();
			
			this.http.shop().post('user/info',{},res=>{
				this.mobile=res.data.mobile;
				this.id = res.data.id;
				this.nickname=res.data.nickname;
				this.avatar=res.data.avatar;
			})
			//#ifdef APP-PLUS
			var that= this
			plus.runtime.getProperty(plus.runtime.appid, (inf) => {
				that.Version = inf.version
			});
			//#endif
		},

		methods: {
		
			changePayPwd() {
				this.changePayPwd(1);
		
			},
            getCode(){
                if(this.mobile==''){
                    this.custom.tool.showToast('请输入手机号码');
                    return false;
                }
                if(!this.custom.tool.checkMobile(this.mobile)){
                    this.custom.tool.showToast('手机号码错误');
                    return false;
                }
                this.http.shop().post('sms-changpay',{mobile:this.mobile},res=>{
                    this.custom.tool.showToast('发送成功');
                },'发送失败',true);
            },
			changeLoginPwd(type) {
				uni.navigateTo({
					url:'/pages/my/setPassword?type='+type+'&mobile='+this.mobile
				})
				
			},
			toAddress(){
				this.custom.tool.jump(0, 'address/index?id='+this.id);
			},
			
			dial() {
				uni.makePhoneCall({
					phoneNumber: this.config.service_mobile
				});
			},
			outlogin() {
				this.custom.tool.clearToken(res=>{
					this.custom.tool.jump(2, 'login/login');
				});
				
				uni.setStorageSync('notice_data',null);
			},
            changeUinfo(type) {
				var avatar= this.avatar.replace('http://zygq.opo5.com','')
				var data ={}
				if(type == 0){
					data = {avatar: avatar}
				}else {
					data = {nickname: this.nickname}
				}
                this.http.requests('user/profile',data , res => {
                    // this.nickname = res.data.nickname
                    // this.avatar = "http://zygq.opo5.com"+this.avatar
					// console.log(res)
					this.custom.tool.showToast(res.msg);
                },"POST")
            },
            uploadImg(type){
				let that = this
			    //修改头像
			    if (type == 1){
					
                    uni.chooseImage({
						count:1,
                        success: (chooseImageRes) => {
                            const tempFilePaths = chooseImageRes.tempFilePaths;
							// let formData =  {
							// 		        'file': new Date().getTime()
							// 		    }
							that.http.upload(tempFilePaths[0],{},res=>{
								// console.log(res)
								 that.avatar = "http://zygq.opo5.com"+res.data
								 that.changeUinfo(0)
							})
							
                        }
                    });
				}
                //修改昵称
                if (type == 2){
                    this.$refs.inputDialog.open()
                }

            },
			dialogInputConfirm(val){
				this.nickname = val
				this.changeUinfo()
			},
            getStorageSize(){
                let that = this;
                uni.getStorageInfo({
                    success(res) {
                        //console.log(res.keys);
                        //console.log(res.limitSize);
                        let size = res.currentSize;
                        if (size < 1024) {
                            that.storageSize = size + ' B';
                        } else if (size/1024>=1 && size/1024/1024<1) {
                            that.storageSize = Math.floor(size/1024*100)/100 + ' KB';
                        } else if (size/1024/1024>=1) {
                            that.storageSize = Math.floor(size/1024/1024*100)/100 + ' M';
                        }
                    }
                })
            },
            clearStorage (){
                let that = this;
                uni.showModal({
                    title:'提示',
                    content:'确定清除缓存吗?',
                    confirmText:'立即清除',
                    success(res) {
                        if(res.confirm){
                            uni.clearStorageSync();
                            //重新获取并显示清除后的缓存大小
                            that.getStorageSize();
                            uni.showToast({
                                title:'清除成功'
                            })
                        }
                    }
                })
            },
            checkUpdate(){
                // if (this.Version <=this.api.version){
                //     uni.showToast({
                //         title:'已经是最新版本'
                //     })
                // } else {
                //     this.api.getVersion(true);
                // }
			}
		}
	}
</script>
<style>
	page {
		background-color: #fff;
	}

	.setting-list {
		
		background-color: #fff;
	}
</style>
<style scoped>
	.list {
		width: 100%;
		margin: 0;
		display: flex;
		flex-flow: column wrap;
		align-items: center;
		height: auto;
		margin-top: 24upx;
	}

	.list-item {
		width: 93%;
		height: 110upx;
		display: flex;
		flex-flow: nowrap row;
		align-items: center;
		justify-content: space-between;
		color: #666666;
		border-bottom: solid 1px #eeeeee;
	}
	.list-item1 {
		width: 95%;
		height: 116upx;
		display: flex;
		flex-flow: nowrap row;
		align-items: center;
		justify-content: space-between;
		color: #666666;
		border-bottom: solid 1px #eeeeee;
	}
	.list-item1>.cl-icon-arrow-right {
		font-size: 32upx;
	}
	.list-item-right {
		font-size: 26upx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #999999;
		display: flex;
		align-items: center;
		flex-flow: nowrap row;
	}
.list-item-text {
		font-size: 30upx;
		color: #414141;
	}
	.list-item>.cl-icon-arrow-right {
		font-size: 32upx;
	}
	.list-item1>.cl-icon-arrow-right {
		font-size: 32upx;
		
	}
	.list-item>.right_to{
		width: 30rpx;
		height: 30rpx;
		object-fit: contain;
	}




	.but {
		background-color: #FE903D;
		border-radius: 10px;
		margin: 100rpx 10px 0rpx 10px;
		font-size: 35rpx;
		padding: 12px 5px;
		font-weight: 400;
		color: #FFFFFF;
		text-align: center;
		//bottom: 30rpx;
		z-index: 2;
		//left: 10%;
	}
	.code-but{
		font-size: 14px;
		margin-top: 13px;
		background-color: #2E73FF;
		text-align: center;
		border-radius: 10px;
		color: #ffffff;
	}
</style>
